<%@ page import="com.work.bean.Middle" %>
<%@ page import="java.util.List" %>
<%@ page import="com.work.entities.Finish" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/10/7
  Time: 20:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>作业进度</title>
</head>
<%@include file="teacher_common.jsp" %>
<script>
    $(function () {
        $("#history_work_li").attr('class', 'active');
    });
</script>

<style>
    #status {
        list-style: none;
        margin-top: 15px;
        margin-left: 375px;
    }

    #status li {
        float: left;
        padding-left: 20px;
        font-size: 20px;

    }

    th, td {
        width: 160px;
        padding: 10px;
        background-color: rgb(180, 193, 224);
    }
</style>

<%
    List<Finish> middles = (List<Finish>) session.getAttribute("middles");

    int pageNumber = (Integer) session.getAttribute("pageNumber");
    int whichPage = (Integer) session.getAttribute("whichPage");
    int countPage = (Integer) session.getAttribute("countPage");
    boolean flag = false;
    if (session.getAttribute("flag") != null) {
        flag = (Boolean) session.getAttribute("flag");
    }
//
//    String menuCategory = "";
//
//    if (session.getAttribute("typeName") != null) {
//        menuCategory = (String) session.getAttribute("typeName");
//    }

    if (session.getAttribute("error") != null) {
        out.print(session.getAttribute("error"));
    }

    int isF = 5;
    if (session.getAttribute("isFinish") != null) {

        isF = Integer.parseInt(String.valueOf(session.getAttribute("isFinish")));
    }

%>
<body>
<div>
    <div>
        <div style="margin-left: 250px">
            <h3 style="margin-top: 50px">学生完成情况</h3>
            <center>
                <ul id="status">
                    <li id="finished" class="li" onclick="chaneStatus(1,this)">已完成</li>
                    <li>|</li>
                    <li id="notFinish" class="li" onclick="chaneStatus(0,this)">未完成</li>
                </ul>
                <br>
                <br>
                <table border="1px" cellspacing="0px" cellpadding="20px" style="margin-left: 10px">


                    <%

                        if (isF == 1) {%>

                    <tr>
                        <th>学生姓名</th>
                        <th>作业文件</th>
                        <th>分数</th>
                    </tr>

                    <%

                        if (middles != null) {
                            for (Finish middle : middles) {%>
                    <tr>
                        <td><%=middle.getUsername()%>
                        </td>
                        <td><%=middle.getFileName()%>

                            <br>
                            <%

                                if (middle.getGrade() != 0) {%>

                            <a href="${pageContext.request.contextPath}/readonline.jsp?readOnlinePath=<%=middle.getReadOnlinePath()%>">预览</a>
                            <%} else {%>

                            <a href="${pageContext.request.contextPath}/readonline.jsp?readOnlinePath=<%=middle.getReadOnlinePath()%>&studentId=<%=middle.getStudentId()%>">预览</a>
                            <%}%>
                            <br>
                            <a href="${pageContext.request.contextPath}/download?path=<%=middle.getStudentSubmitPath()%>">下载</a>

                        </td>
                        <%

                            if (middle.getGrade() != 0) {%>

                        <td><%=middle.getGrade()%>
                        </td>
                        <%} else {%>
                        <td>尚未评分</td>
                        <%
                            }
                        %>
                    </tr>

                    <%
                            }
                        }
                    %>


                    <%} else if (isF == 0) {%>

                    <tr>
                        <th>学生姓名</th>
                    </tr>

                    <%

                        if (middles != null) {
                            for (Finish middle : middles) {%>
                    <tr>
                        <td><%=middle.getUsername()%>
                        </td>

                    </tr>

                    <%
                            }
                        }
                    %>

                    <% }
                    %>


                    <tr>
                        <td colspan="5" align="center">
                            <button onclick="jump('first')">最前页</button>
                            <button onclick="jump('last')">上一页</button>
                            <button onclick="jump('next')">下一页</button>
                            <button onclick="jump('final')">最后页</button>
                            跳转到第<select id="whichPage" onchange="jumpChange(0,this[selectedIndex].value)">
                            <%
                                if (pageNumber != 0) {

                                    for (int i = 0; i < pageNumber; i++) {

                                        if ((i + 1) == whichPage) {
                            %>
                            <option selected="selected"><%=i + 1%>
                            </option>
                            <%
                            } else {%>
                            <option><%=i + 1%>
                            </option>
                            <%
                                        }
                                    }

                                }
                            %>

                        </select>页
                            每页显示
                            <select id="pageCount" onchange="jumpChange(1,this[selectedIndex].value)">

                                <option><%=countPage%>
                                </option>
                                <%

                                    for (int i = 3; i <= 15; i += 3) {
                                        if (i == countPage) {%>

                                <option selected="selected"><%=countPage%>
                                </option>
                                <%} else {%>
                                <option><%=i%>
                                </option>
                                <%
                                        }

                                    }
                                %>
                            </select>条

                        </td>
                    </tr>

                    </tbody>
                </table>
            </center>
        </div>

        <!--//banner-->
    </div>
</div>

</body>

<script type="text/javascript">

    $(function () {

        var status = ${sessionScope.isFinish};

        if (status == 0) {

            $('#notFinish').css('color', 'red');
        } else if (status == 1) {

            $('#finished').css('color', 'red');
        }
    });

    function chaneStatus(t, thisLi) {

        thisLi.style.color = "red";
        $(".li").not(thisLi).css('color', "black");


        window.location = "${pageContext.request.contextPath}/finish?workId=${sessionScope.workId}&isFinish=" + t;

    }

    function deleteById(id) {

        if (confirm("确认删除？")) {
            window.location = "/finish?deleteId=" + id;
            alert("删除成功");
        }
    }

    function jump(type) {

        var objW = document.getElementById("whichPage"); //定位id
        var indexW = objW.selectedIndex; // 选中索引
        var whichPage = objW.options[indexW].text; // 选中文本

        var objP = document.getElementById("pageCount"); //定位id
        var indexP = objP.selectedIndex; // 选中索引
        var pageCount = objP.options[indexP].text; // 选中文本

        if (type == 'first') {

            if (whichPage == 1) {

                alert("当前已是第一页");

            } else {

                window.location = "/finish?countPage=" + pageCount + "&whichPage=1";
            }

        } else if (type == 'last') {

            if (whichPage == 1) {
                alert("当前已是第一页");
            } else {

                window.location = "/finish?countPage=" + pageCount + "&whichPage=" + (whichPage - 1);
            }

        } else if (type == 'next') {

            if (whichPage == <%=pageNumber%>) {

                alert("当前已是最后页");

            } else {

                window.location = "/finish?countPage=" + pageCount + "&whichPage=" + (whichPage - (-1));
            }

        } else if (type == 'final') {

            if (whichPage == <%=pageNumber%>) {
                alert("当前已是最后页");
            } else {

                window.location = "/finish?countPage=" + pageCount + "&whichPage=<%=pageNumber%>";
            }
        }

    }

    function jumpChange(type, value) {

        if (type == 0) {

            var objP = document.getElementById("pageCount"); //定位id
            var indexP = objP.selectedIndex; // 选中索引
            var pageCount = objP.options[indexP].text; // 选中文本

            window.location = "/finish?countPage=" + pageCount + "&whichPage=" + value;

        } else if (type == 1) {

            var objW = document.getElementById("whichPage"); //定位id
            var indexW = objW.selectedIndex; // 选中索引
            var whichPage = objW.options[indexW].text; // 选中文本

            window.location = "/finish?countPage=" + value + "&whichPage=1";

        }
    }

</script>
</html>
